# Makefile for gcc compiler for iPhone

PROJECTNAME=HelloWorld
APPFOLDER=$(PROJECTNAME).app
INSTALLFOLDER=$(PROJECTNAME).app

CC=arm-apple-darwin9-gcc
LD=$(CC)
LDFLAGS = -arch arm -lobjc 
LDFLAGS += -framework CoreFoundation 
LDFLAGS += -framework Foundation 
LDFLAGS += -framework UIKit 
LDFLAGS += -framework QuartzCore
LDFLAGS += -framework CoreGraphics 
LDFLAGS += -framework GraphicsServices 
LDFLAGS += -framework CoreSurface 
//LDFLAGS += -framework CoreAudio 
//LDFLAGS += -framework Celestial 
//LDFLAGS += -framework AudioToolbox 
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
LDFLAGS += -L"/usr/lib"
LDFLAGS += -F"/System/Library/Frameworks"
LDFLAGS += -F"/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress

CFLAGS = -I"/var/include" 
CFLAGS += -I"/usr/include" 
CFLAGS += -F"/System/Library/Frameworks" 
CFLAGS += -F"/System/Library/PrivateFrameworks" 
#CFLAGS += -DDEBUG -O3 -Wall -std=c99 -funroll-loops
CFLAGS += -DDEBUG -Wall -std=c99
CFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1050

BUILDDIR=./build/2.0
SRCDIR=./Classes
RESDIR=./Resources
OBJS=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.cpp,%.o,$(wildcard $(SRCDIR)/*.cpp))
RESOURCES=$(wildcard $(RESDIR)/*)

all:	dist

$(PROJECTNAME):	$(OBJS)
	$(LD) $(LDFLAGS) -o $@ $^

%.o:	%.m
	$(CC) -c $(CFLAGS) $< -o $@

%.o:	%.c
	$(CC) -c $(CFLAGS) $< -o $@

%.o:	%.cpp
	$(CC) -c $(CPPFLAGS) $< -o $@

dist:	$(PROJECTNAME)
	/bin/rm -rf $(BUILDDIR)
	/bin/mkdir -p $(BUILDDIR)/$(APPFOLDER)
	/bin/cp $(RESDIR)/* $(BUILDDIR)/$(APPFOLDER)
	/bin/cp Info.plist $(BUILDDIR)/$(APPFOLDER)/Info.plist
	@echo "APPL????" > $(BUILDDIR)/$(APPFOLDER)/PkgInfo
	/usr/bin/ldid -S $(PROJECTNAME)
	/bin/cp $(PROJECTNAME) $(BUILDDIR)/$(APPFOLDER)

install: dist
	/bin/cp -r $(BUILDDIR)/$(APPFOLDER) /Applications/$(INSTALLFOLDER)
	@echo "Application $(INSTALLFOLDER) installed"
	killall SpringBoard

uninstall:
	/bin/rm -fr /Applications/$(INSTALLFOLDER)
	killall SpringBoard

reinstall: dist
	/bin/rm -fr /Applications/$(INSTALLFOLDER)
	/bin/cp -r $(BUILDDIR)/$(APPFOLDER) /Applications/$(INSTALLFOLDER)
	@echo "Application $(INSTALLFOLDER) installed"

clean:
	@rm -f $(SRCDIR)/*.o
	@rm -rf $(BUILDDIR)
	@rm -f $(PROJECTNAME)

